//操纵数据库的脚本，由于之前蚂蚁森林和农行掌银两个表已经创建了，所以没有记录
//创建皮肤主题字号表
let db = sqlite.open("./data.db", {
    version: 1
}, {
    onOpen: function (db) {
        // 数据库打开时，执行创建数据库表的语句
        //创建正在使用主题皮肤设置表
        db.execSQL("CREATE TABLE IF NOT EXISTS THEMESETTINGS(" +
            "`id` INTEGER PRIMARY KEY AUTOINCREMENT, " +
            "`skinpath` TEXT NOT NULL, " +
            "`bussinesscardpath` TEXT NOT NULL, " +
            "`themecolorcode` TEXT NOT NULL," +
            "`routinecolorcode` TEXT NOT NULL, " +
            "`remindcolorcode` TEXT NOT NULL" +
            ");" +
            //创建蚂蚁森林使用参数表
            "CREATE TABLE IF NOT EXISTS MYSL(" +
            "`id` INTEGER PRIMARY KEY AUTOINCREMENT, " +
            "`shield` BOOLEAN NOT NULL, " +
            "`watering` BOOLEAN NOT NULL," +
            "`doublecard` BOOLEAN NOT NULL" +
            ");" +
            //创建农行掌银密码表
            "CREATE TABLE IF NOT EXISTS ABCZY(" +
            "`id` INTEGER PRIMARY KEY AUTOINCREMENT, " +
            "`password` INTEGER NOT NULL" +
            ");"
        );
        db.execSQL(
            //创建皮肤表
            "CREATE TABLE IF NOT EXISTS SKIN(" +
            "`skinpath` TEXT PRIMARY KEY, " +
            "`skinname` TEXT NOT NULL" +
            ");"
        );
        db.execSQL(
            //创建名片卡图片表
            "CREATE TABLE IF NOT EXISTS bussinesscard(" +
            "`bussinesscardpath` TEXT PRIMARY KEY, " +
            "`bussinesscardname` TEXT NOT NULL);"
        );
        db.execSQL(
            //创建颜色表
            "CREATE TABLE IF NOT EXISTS COLOR(" +
            "`COLORCODE` TEXT PRIMARY KEY, " +
            "`colorname` TEXT NOT NULL);"
        );
    }
});
log("所有表: ", db.rawQuery("select name from sqlite_master where type=? order by name", ["table"]).all());
//初始化皮肤表
function insertSkinFirst() {
    //插入图片数据
    db.insert("SKIN", {
        skinpath: "file://res/侧颜.jpg",//地址
        skinname: "侧颜"//名字
    });
    db.insert("SKIN", {
        skinpath: "file://res/沉默.png",
        skinname: "沉默"
    });
    db.insert("SKIN", {
        skinpath: "file://res/春色.png",
        skinname: "春色"
    });
    db.insert("SKIN", {
        skinpath: "file://res/躲避.jpg",
        skinname: "躲避"
    });
    db.insert("SKIN", {
        skinpath: "file://res/离别的春季.jpg",
        skinname: "离别的春季"
    });
    db.insert("SKIN", {
        skinpath: "file://res/内心下着雨.png",
        skinname: "内心下着雨"
    });
    db.insert("SKIN", {
        skinpath: "file://res/落霞.jpg",
        skinname: "落霞"
    });
    db.insert("SKIN", {
        skinpath: "file://res/尼康.png",
        skinname: "尼康"
    });
    db.insert("SKIN", {
        skinpath: "file://res/世界的半径.png",
        skinname: "世界的半径"
    });
    db.insert("SKIN", {
        skinpath: "file://res/世界终焉.png",
        skinname: "世界终焉"
    });
    db.insert("SKIN", {
        skinpath: "file://res/是谁的谁.png",
        skinname: "是谁的谁"
    });
    db.insert("SKIN", {
        skinpath: "file://res/送花.png",
        skinname: "送花"
    });
    db.insert("SKIN", {
        skinpath: "file://res/夏季少女.jpg",
        skinname: "夏季少女"
    });
    db.insert("SKIN", {
        skinpath: "file://res/烟火.jpg",
        skinname: "烟火"
    });
    db.insert("SKIN", {
        skinpath: "file://res/贞德.jpeg",
        skinname: "贞德"
    });
    db.insert("SKIN", {
        skinpath: "file://res/卒业.png",
        skinname: "卒业"
    });
    db.insert("SKIN", {
        skinpath: "file://res/JOJO.jpg",
        skinname: "JOJO"
    });
}
//初始化名片表
function insertBussinesscardFirst() {
    db.insert("bussinesscard", {
        bussinesscardpath: "file://res/杰洛小熊.jpg",
        bussinesscardname: "侧颜"
    });
    db.insert("bussinesscard", {
        bussinesscardpath: "file://res/雪中对饮.png",
        bussinesscardname: "雪中对饮"
    });
}
//初始化当前数据表
function insertTHEMESETTINGFirst() {
    db.insert("THEMESETTINGS", {
        skinpath: "file://res/烟火.jpg",
        bussinesscardpath: "file://res/烟火.jpg",
        themecolorcode: "#000000",
        remindcolorcode: "#000000",
        routinecolorcode: "#000000"
    });
}
//insertTHEMESETTINGFirst()
//insertSkinFirst()
//insertBussinesscardFirst()
//查询所有数据:
log("皮肤表所有数据: ", db.rawQuery("SELECT * FROM SKIN", null).all());
log("名片卡表所有数据: ", db.rawQuery("SELECT * FROM bussinesscard", null).all());
log("当前设置表所有数据: ", db.rawQuery("SELECT * FROM THEMESETTINGS", null).all());

// 还要关闭数据库
db.close();